/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.progin.drop.server;

import com.progin.drop.core.Message;
import com.progin.drop.core.MessageException;
import com.progin.drop.core.MessageOperator;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HP
 */
public class TestMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //basedir = "E:/xampp/htdocs/progin-1/tugas2/public/files";


        try {
            File targetFile = new File("a.pdf");
            //FileInputStream in = new FileInputStream(targetFile);

            //byte[] b = new byte[(int)targetFile.length()];
            //in.read(b);

            //in.close();

            Socket sock = new Socket("127.0.0.1" , 2000);

            Message m = Message.construct("#2;15#a.pdf;#");
            //m.setByteStream(b);
            System.out.println("Sending message : " + m.toString());

            MessageOperator mo = new MessageOperator(m);

            mo.send(sock);

            StreamHandler handler = new StreamHandler(new File("a.pdf"));
            mo.setHandler(handler);
            m = mo.receive(sock);
            System.out.println(mo.mAttachmentLength);
            mo.loadAttachment(sock);
            //while (true) {}
            //System.out.println(m.getByteStream().length);

            //sock.close();
        } catch (UnknownHostException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        } catch (MessageException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        }

    }
}
